package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.*;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/6/2 15:04
 */
public class LogManorDaoImpl extends TempDao {

    public boolean addLogManorHarvest(List<LogManorHarvest> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_harvest(userId,type,outputId,outputLv,landLv,skinId,buildingArr,guestArr,baseSpeed,yield,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorHarvest data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOutputId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOutputLv()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandLv()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSkinId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getBuildingArr()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getGuestArr()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getBaseSpeed()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getYield()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorSpecialSkillLvUp(List<LogManorSpecialSkillLvUp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_specialskill_lvup(userId,outputId,costNum,lv,time) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorSpecialSkillLvUp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOutputId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getCostNum()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLv()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorSkinLvUp(List<LogManorSkinLvUp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_skin_lvup(userId,belongId,skinId,cost,lv,time) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorSkinLvUp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBelongId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSkinId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getCost()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLv()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorGuestUnLock(List<LogManorGuestUnLock> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_guest_unlock(userId,guestId,time) VALUES(?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorGuestUnLock data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGuestId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorTechnologySkillLvUp(List<LogManorTechnologySkillLvUp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_technologyskill_lvup(userId,technologyId,pos,beforeLv,afterLv,lvUpCount,cost,time) VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorTechnologySkillLvUp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getTechnologyId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPos()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBeforeLv()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getAfterLv()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLvUpCount()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getCost()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorProsperousValueGet(List<LogManorProsperousValueGet> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_prosperousvalue_get(userId,addValue,getWay,time) VALUES(?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorProsperousValueGet data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAddValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getGetWay()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorOutPutLvUp(List<LogManorOutPutLvUp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_output_lvup(userId,outPutId,lvUpCount,lv,removeSliver,time) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorOutPutLvUp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOutPutId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLvUpCount()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLv()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getRemoveSliver()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogManorWeather(List<LogManorWeather> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_manor_weather(weather,endTime,time) VALUES(?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogManorWeather data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getWeather()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getEndTime()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
